<?php

  /*
   * dao.php
   * author: daniel rudigier
   * date: 20.5.08
   * 
   * change the generator in hibernate's xml mappings
   * 
   * love it or hate it!
   */

  $genclass = "ocumed.persistenz.hibernate.TriggerAssignedIdentityGenerator";
  $genclass = "assigned ";
  $genclass = "sequence";
  $genclass = "sequence-identity"; // oracle
  $genclass = "increment"; 
  $gen = "<generator class=\"$genclass\" />";

  $inputdir = "./src/ocumed/persistenz/hibernate";
  $outputdir = $inputdir;
  
  // open the directory
  if (is_dir($inputdir)) {
    if ($dh = opendir($inputdir)) {
      while (($file = readdir($dh)) !== false) {
        if (is_file($inputdir . '/' . $file)) {
          
          // copy the xml schemas
          if (strpos($file, '.xml') !== false) {
            echo "mapping: " . $file . "\n";
            $str = file_get_contents($inputdir . '/' . $file);
            
            $str = preg_replace("/<generator[^>]+>/", $gen, $str);
            
            $fh = fopen($outputdir . '/' . $file, 'wb');
            fwrite($fh, $str);
            fclose($fh);
          }
        }
      }
    }
  }

?>